#include "SpriteMoney.h"
#include "../../game/userManage/userinfo.h"

CSpriteMoney::CSpriteMoney(void)
{
	setSRbodyType(CSRBODY_TYPE_MONEY);
}

CSpriteMoney::~CSpriteMoney(void)
{
}

CSpriteMoney* CSpriteMoney::spriteWithFile( const char *pszFileName )
{
	CSpriteMoney *pobSprite = new CSpriteMoney();
	if (pobSprite && pobSprite->initWithFile(pszFileName))
	{
		pobSprite->autorelease();
		return pobSprite;
	}
	CC_SAFE_DELETE(pobSprite);
	return NULL;
}

CSpriteMoney* CSpriteMoney::spriteWithRBodyFile(float density,const CCPoint& pos,const char *pszFileName)
{

	CSpriteMoney* spr = spriteWithFile(pszFileName);


	if (spr)
	{

		spr->setPosition(pos);

		CCSize boxSize = CCSizeMake(spr->getContentSizeInPixels().width,spr->getContentSizeInPixels().height);

		b2BodyDef paddleBodyDef;

		paddleBodyDef.userData = spr;

		paddleBodyDef.type = b2_dynamicBody;
		paddleBodyDef.position.Set(spr->getPositionInPixels().x/PTM_RATIO,spr->getPositionInPixels().y/PTM_RATIO);
		b2Body *m_paddleBody = Cbox2dManage::s_world->CreateBody(&paddleBodyDef);


		b2PolygonShape paddleShape;
		paddleShape.SetAsBox(boxSize.width/PTM_RATIO/2.0f,boxSize.height/PTM_RATIO/2.0f);

		b2FixtureDef paddleShapeDef;
		paddleShapeDef.shape = &paddleShape;
		paddleShapeDef.density = density;

		paddleShapeDef.filter.categoryBits = CATEGORYBITS_MONEY;
		paddleShapeDef.filter.maskBits = MASKBITS_MONEY;



		spr->setFixture(m_paddleBody->CreateFixture(&paddleShapeDef));
		Cbox2dManage::s_Buoyancy->AddBody(m_paddleBody);

	}


	return spr;

}

void CSpriteMoney::updatelogic()
{


}
void CSpriteMoney::updateHitLogic()
{
	switch(gethitType())
	{
		case CSRBODY_TYPE_COCONUT:
			{
				CCLog("hit money");

				DestroyBuoyancyRbody();

				this->removeFromParentAndCleanup(true);

				userinfo::SharedInstance()->addMoney(20);


			}
			break;
	}

}